<?php

/*
 * get all general definitions
 */
define('ROOT_PATH', realpath(dirname(dirname(__FILE__))));
//echo ROOT_PATH.'<br />';
define('APPLICATION_PATH', ROOT_PATH . "/application");
//echo APPLICATION_PATH.'<br />';
define('PUBLIC_PATH', ROOT_PATH . '/public');
//echo PUBLIC_PATH.'<br />';
define('CONFIG_PATH', ROOT_PATH . "/configs");
//echo CONFIG_PATH.'<br />';
define('LIBRARY_PATH', realpath(dirname(ROOT_PATH)) ."/library" );
//echo LIBRARY_PATH.'<br />';
define('PRODUCT', basename(dirname(__FILE__)));
//echo PRODUCT.'<br />';
//define('LOG_PATH', PUBLIC_PATH . DIRECTORY_SEPARATOR . PRODUCT . DIRECTORY_SEPARATOR . '/logs');
//echo LOG_PATH.'<br />';

/*
 * Define application environment
 */
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ?
        getenv('APPLICATION_ENV') : 'production'));

// Ensure library/ is on include_path
function myAutoloader($class) {
    $path = LIBRARY_PATH . DIRECTORY_SEPARATOR .str_replace('_', DIRECTORY_SEPARATOR, $class). '.php';
    if(strpos($class, 'Model_')===0){
        $path = APPLICATION_PATH . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $class). '.php';
        $path = str_replace('Model'.DIRECTORY_SEPARATOR, 'models'.DIRECTORY_SEPARATOR, $path);				
	}
    
    //include file
    if(is_file($path)){
        include_once($path);
    }
}
spl_autoload_register('myAutoloader');
set_include_path(LIBRARY_PATH);
date_default_timezone_set('Asia/Saigon');

//define mode display
if(isset($argv[1]) && $argv[1] == '-s'){
    define('SHOW_PROGRESS', 1);
}else{
    define('SHOW_PROGRESS', 0);
}

function pr()
{
    $numargs = func_num_args();
    $data = func_get_args();
    if($numargs == 1){
        $data = $data[0];
    }

    $trace = debug_backtrace();
    $caller = array_shift($trace);
    echo "called by [{$caller['file']}] line: {$caller['line']}\n";
    var_dump($data);
}

function prd()
{
    $numargs = func_num_args();
    $data = func_get_args();
    if($numargs == 1){
        $data = $data[0];
    }

    $trace = debug_backtrace();
    $caller = array_shift($trace);
    echo "called by [{$caller['file']}] line: {$caller['line']}\n";
    var_dump($data);
    exit;
}
/*
 * get ccu mining controller
 */


require_once(APPLICATION_PATH . '/controllers/EmailController.php');
$controller = new EmailController();

$controller->equipmentnotify();
$controller->equipmenttrack();